package com.shitou.shitoucommons.utils;


import lombok.Data;
import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * 作为所有项目的返回集
 */
@Data
@SuppressWarnings("all")
public class RespBean extends HashMap<String, Object> {

    public RespBean(){
        put("code", 200);
        put("message", "success");
    }

    public RespBean(String message){
        put("code", 200);
        put("message", message);
    }

    public RespBean(int code, String message){
        put("code", code);
        put("message", message);
    }

    public static RespBean error(int code, String message){
        RespBean respBean = new RespBean();
        respBean.put("code", code);
        respBean.put("message", message);
        return respBean;
    }

    /**
     * 500错误
     * @param message
     * @return
     */
    public static RespBean error(String message){
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, message);
    }

    public static RespBean error(){
        return error("系统未知异常，请联系管理员");
    }



    public static RespBean success(Map<String, Object> map){
        RespBean respBean = new RespBean();
        respBean.putAll(map);
        return respBean;
    }
    public static RespBean success(){return new RespBean();}
    public static RespBean success(String message){
        return new RespBean(message);
    }
    public static RespBean success(int code, String message){
        return new RespBean(code, message);
    }


    public RespBean put(String key, Object value){
        super.put(key, value);
        return this;
    }
}
